<?php
$this->set('title_for_layout',$event['Event']['name']);
$this->set('description_for_layout',$this->Text->truncate(
        Sanitize::clean(Sanitize::stripWhitespace($event['Event']['desc']),array(
            'encode' => true, 
            'remove_html'=>true, 
            'odd_spaces'=>true, 
            'carriage'=>true)), 250, array(
                'ending' => '...',
                'exact' => false,
                'html' => false)));
$now = time();
$inSeconds = $this->Timepl->fromString($event['Event']['startdate']);
$inFuture = ($inSeconds > $now);

?><div class="event-page">
    <a class="right gbutton green share-button-intent hidden" data-url="<?=$this->Html->url(array(),true)?>" href="#">Udostępnij</a>
    <?php if($event['Event']['accepting'] == '1' && $inFuture): ?>
    <a class="right gbutton green hidden" data-eventid="<?=$event['Event']['id']?>" href="#">Chcę tam być</a>
    <?php endif; ?>
    
    <h1><?=$event['Event']['name']?></h1>
    <div class="meta">
        <span class="time">
            <span class="callendar-image"></span>
            <?=$this->Timepl->niceShort($event['Event']['startdate'])?>
        </span>
        <?php
            
            $timeFormat = 'Ymd\THis\Z';
            $calendarEntry = 'http://www.google.com/calendar/event?action=TEMPLATE&text=';
            $calendarEntry .= urlencode($event['Event']['name']);
            $calendarEntry .= '&dates=' . CakeTime::format($timeFormat, $event['Event']['startdate'], true, 0) . '/' . CakeTime::format($timeFormat, $event['Event']['startdate'], true, 0);
            $calendarEntry .= '&details=' . urlencode($this->Text->truncate(Sanitize::html($event['Event']['desc'], array('remove' => true)), 100, array('ellipsis' => '...','exact' => true,'html' => false)));
            if(!empty($event['Place'])){
                if(!empty($event['Place']['Address'])){
                    $calendarEntry .= '&location=' . urlencode($event['Place']['Address']['postal'] . ', ' . $event['Place']['Address']['city']);
                } else {
                    $calendarEntry .= '&location=' . urlencode($event['Place']['name']);
                }
            }
            $calendarEntry .= '&trp=true';
            $calendarEntry .= '&sprop=' . urlencode($this->Html->url($this->here, true));
            $calendarEntry .= '&sprop=name:GDG%20Polska';
        ?>
        <a href="<?=$calendarEntry?>" target="_blank" class="gbutton blue calendarButton">
            <span class="plus"></span>
            Dodaj do kalendarza
        </a>
        
        <?php if(!empty($event['Place'])): 
            $hasWebsite = $event['Place']['url'] != null;
        ?>
        <span class="place">
            <?php if ($hasWebsite){ ?><a class="gbutton blue" href="<?=$event['Place']['url']?>" target="_blank" rel="nofollow"><?php } ?>
            <?=$event['Place']['name']?>
            <?php if ($hasWebsite){ ?></a><?php } ?>
        </span>
        <?php if(!empty($event['Place']['Address'])): ?>
        <span class="map-link">
            <a class="gbutton blue" target="_blank" rel="noffolow" href="https://maps.google.com/maps?q=<?=urlencode($event['Place']['Address']['postal'] . ', ' . $event['Place']['Address']['city'])?>">mapa</a>
        </span>
        <?php endif; ?>
        <?php endif; ?>
    </div>
    <div class="share">
        <div class="item">
            <div class="fb-like" data-send="false" data-layout="button_count" data-width="120" data-show-faces="false" data-action="recommend"></div>
        </div>
        <div class="item">
            <div class="g-plusone" data-width="300" data-annotation="inline"></div>
        </div>
    </div>
    <div class="desc">
        <?=$event['Event']['desc']?>
    </div>
</div>